package com.kejiguan.ui.presenter;

import android.widget.Toast;

import com.android.volley.error.VolleyError;
import com.android.volley.response.Response;
import com.kejiguan.ui.request.GsonRequest;
import com.kejiguan.ui.request.RequestUtil;
import com.kejiguan.ui.response.GetNeItemInfosResponse;
import com.kejiguan.ui.util.CommonDate;
import com.kejiguan.ui.util.DateFormatUtil;

import org.greenrobot.eventbus.EventBus;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by YYY on 2016/5/1.
 */
public class NeItemRealMonitorPresenter extends BaseFragmentPresenter{

    public void getNeItemInfos() {

        long currentTime = System.currentTimeMillis();
        String currentDate = String.valueOf(currentTime);
        try {
            currentDate = DateFormatUtil.longToString(currentTime, "yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }

        Map<String, String> params = new HashMap<>();
        params.put("requestCode", "703");
        params.put("messageId", currentDate + "S" + currentTime);
        params.put("systemCode", CommonDate.SystemCode);

        final GsonRequest<GetNeItemInfosResponse> request = new GsonRequest("getNeItemInfos", GetNeItemInfosResponse.class, new Response.Listener<GetNeItemInfosResponse>() {
            @Override
            public void onResponse(GetNeItemInfosResponse response) {
                EventBus.getDefault().post(response);


            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(mContext, "获取网元信息失败", Toast.LENGTH_SHORT).show();
            }
        });

        RequestUtil.sendRequest(mContext, params, request);
    }
}
